/**
 *Essa classe e responsavel pelas atualizacoes do agents rock n roll racing do tipo topdown view
 */
import corejuliano.gameelement.agent.perspective.*; 
import corejuliano.designpattern.mvc.*;
import corejuliano.*;

import util.*;
import flash.geom.*;

import rocknrollracing.gameelement.agent.*;
import rocknrollracing.gameelement.*;
import rocknrollracing.phase.*;
 
class rocknrollracing.gameelement.agent.perspective.RocknRollRacingAgentTopDownViewPixel extends GameElementView  
{
	public function RocknRollRacingAgentTopDownViewPixel(canvas:MovieClip, model:Model)
	{
		super(canvas, model);
	}
	
	
	public function destroy():Void
	{
		super.destroy();
	}
	
	public function updateScreen():Void
	{
		var oldPositionX:Number = graphic._x;
		var oldPositionY:Number = graphic._y;
		var oldRotation:Number = graphic._rotation; 
		
		var gameElements:Array = RocknRollRacingPhase(GameManager.getInstance().getActivePhase()).getGameElements();
		
		graphic._rotation = RocknRollRacingAgentModel(model).getRotation();
		graphic._x = model.getPosition().x;
		graphic._y = model.getPosition().y;
		
		
		Logger.trace("Rotation: " + RocknRollRacingAgentModel(model).getRotation());
		var movieclip:MovieClip = GameElementModel(model).getGraphic();
					
		for(var i = 0; i < gameElements.length; i++)
		{
			// testa se e solido o movieclip e e se nao e o proprio carro :D
			if (gameElements[i].isSolid() && gameElements[i].getModel().getGraphic() != movieclip)
			{
				if (movieclip.hitTest(gameElements[i].getModel().getGraphic()))
				{
					graphic._x = oldPositionX
					graphic._y = oldPositionY
					graphic._rotation = oldRotation;
					
					model.setPosition( new Point(graphic._x, graphic._y));
					RocknRollRacingAgentModel(model).setRotation(oldRotation);
				}				
			}	
		}
				
	}
	
	public function toString():String
	{
		return "rocknrollracing.gameelement.agent.perspective.RocknRollRacingAgentTopDownView";
	}	
	
}